package org.example.controller;

import io.swagger.annotations.Api;
import org.example.annotation.mySystemlog;
import org.example.enmus.AppHttpCodeEnum;
import org.example.domain.entity.User;
import org.example.domain.result.ResponseResult;
import org.example.exception.SystemException;
import org.example.service.BlogLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;


/**
 * @author lemon
 */
@RestController
@Api(tags = "登录接口")
public class BlogLoginController {

    @Autowired
    private BlogLoginService blogLoginService;

    @PostMapping("/login")
    @mySystemlog(businessName = "登录")
    public ResponseResult login(@RequestBody User user){
        if(!StringUtils.hasText(user.getUserName())){
            //提示 必须要传用户名
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return blogLoginService.login(user);
    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        return blogLoginService.logout();
    }

}
